﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;

using Jarvis.Analytics;
using Jarvis.Learners;

namespace Jarvis.Windows
{
    /// <summary>
    /// Interaction logic for LearnersWindow.xaml
    /// </summary>
    public partial class LearnersWindow : Window
    {
        public LearnerManager learnerManager = null;

        public LearnersWindow()
        {
            InitializeComponent();

            this.learners.SelectedIndex = -1;
        }

        protected override void OnActivated(EventArgs e)
        {
            if (this.learners.SelectedIndex == -1)
                this.learners.SelectedIndex = 0;
        }

        public void LearnersUpdated(object obj, EventArgs eventArgs)
        {
            this.learners_SelectionChanged(null, null);
        }

        private void learners_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.learners.SelectedIndex != -1)
            {
                String learner = (learners.SelectedValue as ComboBoxItem).Content.ToString();
                this.Title = "Machine Learner: " + learner;

                if (learnerManager != null)
                {
                    String learnerText = learnerManager.TextForLearner(learner);
                    LearnerView.Text = learnerText;
                }
            }
        }

        private void Window_Closing(object sender, CancelEventArgs e)
        {
            Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                (DispatcherOperationCallback)delegate(object o)
                {
                    Hide();
                    return null;
                }, null);

            AnalyticsManager.LogEvent("Window Closing", "Learners");

            e.Cancel = true;
        }
    }
}
